#include "ScopePrinter.h"

#include<iostream>
#include<string>

using namespace std;

string g_asType[]=
{
    "Invalid",
    "Global/File",
    "Parentheses",
    "C-Style Comment",
    "C++-style Comment",
    "Block",
    "Bracket",
    "ePreprocessor" //FIXME Remove this. This is actually intelligence?
};


void ScopePrinter::tabify()
{
    for(int i=0;i<m_nIndent;i++)
        cout<<" ";
}


ScopePrinter::ScopePrinter(void)
{
	m_nIndent = 0;
	m_nLineNumber = 1;
}

ScopePrinter::~ScopePrinter(void)
{
}

void ScopePrinter::onNewToken(Token& inToken)
{
	if('\n'==char(inToken))
	{
		m_nLineNumber++;
	}
    cout<<inToken.m_sValue;
}


void ScopePrinter::onScopeEntry(Scope& inNewScope, Scope& inOldScope)
{
	cout<<m_nLineNumber<<":";
    tabify();
    cout<<"<<SCOPE>>"<<g_asType[inOldScope.m_eType]<<"-->"<<g_asType[inNewScope.m_eType]<<endl;
    m_nIndent++;
}

void ScopePrinter::onScopeExit(Scope& inNewScope, Scope& inOldScope)
{
	cout<<m_nLineNumber<<":";
    tabify();
    cout<<"<<SCOPE>>"<<g_asType[inOldScope.m_eType]<<"-->"<<g_asType[inNewScope.m_eType]<<endl;
    m_nIndent--;
}

